﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MaxZhang.EasyEntities.Dynamic.Aop
{
    /// <summary>
    /// AOP类型信息
    /// </summary>
    public class AopClassInfo
    {
        public AopClassInfo(string name)
        {
            _name=name;
        }

        private string _name;

        private List<AopMethodInfo> _methods = new List<AopMethodInfo>(8);

        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }

        public List<AopMethodInfo> MethodList
        {
            get
            {
                return _methods;
            }
        }

        /// <summary>
        /// 得到指定方法名的AOP信息
        /// </summary>
        /// <param name="name">方法名称</param>
        /// <returns>方法信息</returns>
        public AopMethodInfo GetMethodInfoByName(string name)
        {
            var item = (from m in _methods
                        where m.Name.Equals(name)
                        select m).FirstOrDefault();
            return item;
        }

        /// <summary>
        /// 向类型信息中添加方法信息
        /// </summary>
        /// <param name="methodname">方法名称</param>
        /// <returns>是否添加成功</returns>
        public bool AddMethodInfo(string methodname)
        {
            var item = GetMethodInfoByName(methodname);
            if (item != null)
                return false;
            _methods.Add(new AopMethodInfo(methodname));
            return true;
        }

        /// <summary>
        /// 向类型信息中添加方法信息
        /// </summary>
        /// <param name="methodname">方法名称</param>
        /// <returns>是否添加成功</returns>
        public bool AddMethodInfo(AopMethodInfo methodinfo)
        {
            var item = GetMethodInfoByName(methodinfo.Name);
            if (item != null)
                return false;
            _methods.Add(methodinfo);
            return true;
        }


        /// <summary>
        /// 删除方法信息
        /// </summary>
        /// <param name="methodname">方法信息名称</param>
        /// <returns>是否删除成功</returns>
        public bool RemoveMethodInfo(string methodname)
        {
            var item = GetMethodInfoByName(methodname);
            if (item == null)
                return false;
            return _methods.Remove(item);
        }

    }
}
